<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../static/font/iconfont.css"/>
		<link rel="stylesheet" type="text/css" href="../static/css/public.css"/>
		<link rel="stylesheet" type="text/css" href="../static/css/logo.css"/>
		<link rel="stylesheet" type="text/css" href="../static/css/zuce.css"/>
		<script type="text/javascript" src="../static/js/jquery-1.11.3.min.js"></script>
		<script type="text/javascript" src="../static/js/sweetalert.min-2.1.2.js"></script>
		<script type="text/javascript" >
			$(function(){
				$("body").parent().css("overflow-y","hidden");
				$("#registerBtn").click(function(){
					var username = $("#username").val().trim();
					if(username.length<=0){
						swal("提示","请输入用户名", "error").then(function (isOk){});
						return;
					}
					var vcode = $("#vcode").val().trim();
					if(vcode.length<=0){
						swal("提示","请输入验证码", "error").then(function (isOk){});
						return;
					}
					if(vcode.length!=6){
						swal("提示","验证码输入有误", "error").then(function (isOk){});
						return;
					}
					var password = $("#password").val().trim();

					if(password.length<6){
						swal("提示","密码长度必须大于六位", "error").then(function (isOk){});
						return;
					}
					var check = $("#check").is(':checked');
					if(!check){
						swal("提示","请同意用户协议，否则无法注册成为系统用户", "error").then(function (isOk){});
						return;
					}
					var emailEndWith = $("#emailType option:selected").val() ;
					$.ajax({
						url:"../user.do?action=register",
						data: {
							username:username+emailEndWith,
							vcode:vcode,
							password:password
						},
						dataType:"text",
						success:function(data){
							var result = JSON.parse(data)
							if(result.code == "2"){
								//4.向用户响应数据（成功，失败）
								swal("提示",result.message, "success").then(function (isOk){
									location.href="../gateway?action=login";
								});
							}else{
								swal("警告",result.message , "error").then(function (isOk){});
							}
						},
						error:function(data){
							console.log(data);
						}
					})

				});
				$("#getVcode").click(function(event){
					event.preventDefault();
					var username = $("#username").val().trim();
					var emailType = $("#emailType option:selected").val() ;
					if(username.length<=0){
						swal("警告","请输入邮箱账号" , "error").then(function (isOk){});
						return;
					}
					var dataInfo = {
						email:username+emailType,
					}
					$.ajax({
						url:"../email.do?action=sendEmailCode",
						data:dataInfo,
						dataType:"text",
						success:function(data){
							var result = JSON.parse(data)
							if(result.code == "1"){
								//4.向用户响应数据（成功，失败）
								swal("提示",result.message, "success").then(function (isOk){});
							}else{
								swal("警告",result.message , "error").then(function (isOk){});
							}
						},
						error:function(data){
							console.log(data);
						}
					})
				});
			});
		</script>
	</head>
	<body>
		<jsp:include page="header.jsp"/>
		<div class="head">
			<div class="banner">
				<div><img src="../uploadFile/images/26.png"></div>
				<div><img src="../uploadFile/images/27.png"></div>
				<div><img src="../uploadFile/images/28.png"></div>
			</div>
		</div>
		<div class="bg"></div>
		<div class="logobox">
			<h1>注册</h1>
			<form action="#" method="post">
				<div class="logolable"><lable>邮箱</lable></div>
				<div class="logoinput">
					<div style="width:calc(68% - 20px)"><input type="text" id="username" style="border:0px solid white"></div>
					<div style="width:25%;padding-left:0px;padding-right:20px">
						<select style="border:0px solid white" id="emailType">
							<option>@qq.com</option>
							<option>@163.com</option>
						</select>
					</div>
				</div>
				<div class="logolable"><lable>获取验证码</lable></div>
				<div class="logoduanxin">
					<input type="text" id="vcode">
					<button id="getVcode">获取验证码</button>
				</div>
				<div class="logolable"><lable>设置密码</lable></div>
				<div class="logomima"><input type="text" id="password"/></div>
				<div class="logoxieyi">
					<input type="checkbox" id="check"/>
					<span>已阅读并接受<a href="#">（注册协议）</a></span>
				</div>
				<div class="logobutton" id="registerBtn">注册</div>
			</form>
			<div class="logocaozuo">
				<div><a href="#"></a></div>
				<div><a href="../gateway?action=login">已有账号?去登录</a></div>
			</div>
		</div>
	</body>
</html>
